package com.weyoung.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.weyoung.app.dto.resp.UserDetailRespDTO;
import com.weyoung.common.model.entity.UserDetailDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface UserDetailMapper extends BaseMapper<UserDetailDO> {
 @Select("SELECT " +
            "    ud.user_id, " +
            "    u.username, " +
            "    f.family_name, " +
            "    ud.real_name, " +
            "    ud.gender, " +
            "    ud.phone, " +
            "    ud.email, " +
            "    ud.birth_date, " +
            "    ud.death_date, " +
            "    ud.is_alive, " +
            "    fud.real_name AS father_name, " +
            "    mud.real_name AS mother_name, " +
            "    ud.address_info " +
            "FROM " +
            "    user_detail ud " +
            "JOIN " +
            "    user u ON ud.user_id = u.user_id " +
            "LEFT JOIN " +
            "    user_detail fud ON ud.father_user_id = fud.user_id " +
            "LEFT JOIN " +
            "    user_detail mud ON ud.mother_user_id = mud.user_id " +
            "LEFT JOIN " +
            "    family f ON u.family_id = f.family_id " +
            "WHERE " +
            "    ud.user_id = #{userId}")
 UserDetailRespDTO getUserDetailById(String userId);

 @Update("UPDATE user_detail SET generated_video_url = #{videoUrl}, update_date = NOW() WHERE user_id = #{userId}")
 void updateGeneratedVideoUrl(@Param("userId") Integer userId, @Param("videoUrl") String videoUrl);
}
